<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background-color: #f2f2f2;
        }

        canvas {
            background-color: #fff;
        }
    </style>
</head>

<body>
    <canvas id="myCanvas" width="400" height="300">
        您的浏览器不支持 Canvas
    </canvas>
    <script>
        var canvas = document.getElementById('myCanvas');
        var ctx = canvas.getContext('2d');

        // var gradient = ctx.createLinearGradient(0, 0, 200, 0);
        // gradient.addColorStop(0, 'green');
        // gradient.addColorStop(1, 'white');
        // ctx.fillStyle = gradient;
        // ctx.fillRect(10, 10, 200, 100);
        var gradient = ctx.createRadialGradient(100, 100, 50, 100, 100, 100);
gradient.addColorStop(0, 'white');
gradient.addColorStop(1, 'green');
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 200, 200);
    </script>
</body>

</html>